﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script src="../../Scripts/common/jquery.leanModal.min.js" type="text/javascript"></script>
        <style type="text/css">
        #lean_overlay { position: fixed; z-index: 100; top: 0px; left: 0px; height: 100%; width: 100%; background: #000; display: none; }
        #OpenWindow { font-size:12px; background: none repeat scroll 0 0 #FFFFFF; border-radius: 5px 5px 5px 5px; box-shadow: 0 0 4px rgba(0, 0, 0, 0.7); display: none; padding-bottom: 2px; width: 500px; z-index: 11000; left: 50%; margin-left: -202px; opacity: 1; position: fixed; top: 200px;}
        #OpenWindow-header { background: url("../../img/hd-bg.png") repeat scroll 0 0 transparent; border-bottom: 1px solid #eeeeee; border-top-left-radius: 5px; border-top-right-radius: 5px; padding: 10px; }
        #OpenWindow-header h2{margin-left:10px;}
        .modal_close { background: url("../../img/modal_close.png") repeat scroll 0 0 transparent; display: block; height: 14px; position: absolute; right: 12px; top: 12px; width: 14px; z-index: 2; }
 
        #OpenWindow .txt-fld { border-bottom: 1px solid #EEEEEE; padding: 8px 6px; position: relative; text-align: left; width: 444px;cursor:pointer;}
        #OpenWindow .txt-fld label { padding-left: 15px;color:Black;}
        </style>
<script type="text/javascript" language="JavaScript">
    var userCard = { uc_id: 0, uc_card: "", uc_pass: "", uc_times: 0, uc_useful: 0, uc_chargeMode: 0, uc_state: 0, uc_kf: 0, uc_yj: 0, uc_bz: "" };
    var mylist, cardType = [], cardState = [];
    var regular_input = {
        uc_card: { exp: /^.{1,1000}$/, m: "请输入充值卡号,多个卡号以，分隔" },
        uc_chargeMode: { exp: /^[0-9]\d*$/, m: "请选择充值卡类型" }
    }
    var mainForm = "";
    $(document).ready(function () {
        $(".txt-fld").mousemove(function (o) {
            $(this).css("background-color", "#cccccc");
        });
        $(".txt-fld").mouseout(function (o) {
            $(this).css("background-color", "#ffffff");
        });
        //mainForm = $("#mainForm").html();
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        function ajax() {
            var card = $.trim($("#seekForm :input[name=card]").val());
            var in_s = $.trim($("#seekForm :input[name=in_s]").val());
            var in_e = $.trim($("#seekForm :input[name=in_e]").val());
            var sx_s = $.trim($("#seekForm :input[name=sx_s]").val());
            var sx_e = $.trim($("#seekForm :input[name=sx_e]").val());
            var dq_s = $.trim($("#seekForm :input[name=dq_s]").val());
            var dq_e = $.trim($("#seekForm :input[name=dq_e]").val());
            var state = $.trim($("#seekForm :input[name=selState]").val());
            var type = $.trim($("#seekForm :input[name=selType]").val());
            var ordercard = $("#seekForm :input[name=ordercard]").attr("checked") ? "1" : "-1";
            var ordertype = $("#seekForm :input[name=ordertype]").attr("checked") ? "1" : "-1";
            var orderstate = $("#seekForm :input[name=orderstate]").attr("checked") ? "1" : "-1";
            var orderdate = $("#seekForm :input[name=orderdate]").attr("checked") ? "1" : "-1";
            var orderuser = $("#seekForm :input[name=orderuser]").attr("checked") ? "1" : "-1";
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage, card: card, in_s: in_s, in_e: in_e,
                type: type, state: state, sx_s: sx_s, sx_e: sx_e, dq_s: dq_s, dq_e: dq_e,
                ordercard: ordercard, ordertype: ordertype, orderstate: orderstate, orderdate: orderdate, orderuser: orderuser
            };
            $.post("/userCard/getUserCard.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            $("#mainTable tbody[name=mainlist]").html("");
            $.each(list, function (i, n) {
                sp.push('<tr>');
                sp.push('<td>' + n.uc_card + '</td>');
                sp.push('<td>' + cardType["x" + n.uc_chargeMode] + '</td>');
                sp.push('<td>' + cardState["x" + n.uc_state] + '</td>');
                sp.push('<td>' + (n.c_startTime == null ? "-" : n.c_startTime.Format("yyyy-MM-dd")) + '</td>');
                sp.push('<td>' + (n.uc_kf == null ? "-" : n.uc_kf) + '</td>');
                sp.push('<td>' + (n.uc_yj == null ? "-" : n.uc_yj) + '</td>');
                sp.push('<td>' + n.uc_bz + '</td>');
                sp.push('<td>' + n.O_Workid + '</td>');
                var ucJson = $.toJSON(n);
                sp.push("<td><a href='#mainForm' onclick='edit(" + n.uc_id + ")' name='linkEdit' vid='" + n.uc_id + "'>修改</a>&nbsp");
                sp.push("<a href='#mainForm' onclick='del(" + n.uc_id + "," + n.uc_card + ")' name='linkDel' >删除</a>&nbsp");
                sp.push("<a href='#OpenWindow' rel='leanModal' onclick='javascript:detail(" + ucJson + ")' name='linkEdit'>注销</a></td>");
                sp.push('</tr>');
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
            $('a[rel*=leanModal]').leanModal({ top: 100, closeButton: ".modal_close" });
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        $("input[name=buttReset]").click(function () {
            $("input[name=uc_card]").val('');
            $("input[name=uc_pass]").val('');
            $("select[name=uc_chargeMode]").val('');
            $("input[name=uc_times]").val('0');
            $("input[name=uc_useful]").val('0');
        });
        $("input[name=buttsend]").click(function () {
            if ($("#textCard").val() == "") {
                alert("请填写或生成编号");
                $("#textCard").focus();
                return false;
            }
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(userCard, "#mainForm");
            $.post("/userCard/saveUserCard.html", { userCard: $.toJSON(userCard), card: $("#textCard").val() }, function (dta) {
                if (dta == "\"-1\"") {
                    alert("保存成功");
                    window.parent.frames["rightFrame"].location.reload();
                    ajax();
                } else {
                    alert("保存成功,卡号" + dta + "重复"); ;
                    window.parent.frames["rightFrame"].location.reload();
                    ajax();
                }
            });

        });
        ajax();
        $("#uc_chargeMode").change(function () {
            if (this.value == 0) {
                $("#uc_times").val(2);
                $("#uc_useful").val(1);
            }
            else if (this.value == 1) {
                $("#uc_times").val(12);
                $("#uc_useful").val(3);
            }
            else if (this.value == 2) {
                $("#uc_times").val(24);
                $("#uc_useful").val(6);
            }
            else if (this.value == 3) {
                $("#uc_times").val(48);
                $("#uc_useful").val(12);
            }
            else if (this.value == 4) {
                $("#uc_times").val(0);
                $("#uc_useful").val(6);
            }
            else if (this.value == 4) {
                $("#uc_times").val(0);
                $("#uc_useful").val(12);
            }
        });

        //
        $("input[name=GenerateCard]").click(function () {
            var cards = $("#txtcards");
            var carde = $("#txtcarde");
            if (cards.val() == "") {
                alert("请填写开始编号");
                cards.focus();
                return false;
            } else if (!/^(\-|\+)?\d+(\.\d+)?$/.test(cards.val())) {
                alert("开始编号格式不正确");
                cards.focus();
                cards.select();
                return false;
            }
            if (carde.val() == "") {
                alert("请填写结束编号");
                carde.focus();
                return false;
            } else if (!/^(\-|\+)?\d+(\.\d+)?$/.test(carde.val())) {
                alert("结束编号格式不正确");
                carde.focus();
                carde.select();
                return false;
            }
            if (parseInt(carde.val()) < parseInt(cards.val())) {
                alert("结束编号不能小于开始编号");
                cards.focus();
                return false;
            }
            $.post("/usercard/GenerateCard.html", { cards: cards.val(), carde: carde.val() }, function (dta) {
                $("#textCard").val(dta);
            });
        });
        $("input[name=buttloginout]").click(function () {
            var id = $("#hiducid").val();
            var card = $("#hiducard").val();
            var kf = $("#txtkf");
            var yj = $("#txtyj");
            var bz = $("#txtbz");
            if (kf.val() == "") {
                alert("请填写退还费用");
                kf.focus();
                return false;
            } else if (!/^(\-|\+)?\d+(\.\d+)?$/.test(kf.val())) {
                alert("退还费用格式不正确");
                kf.focus();
                kf.select();
                return false;
            }
            if (yj.val() == "") {
                alert("请填写退还押金");
                yj.focus();
                return false;
            } else if (!/^(\-|\+)?\d+(\.\d+)?$/.test(yj.val())) {
                alert("退还押金格式不正确");
                yj.focus();
                yj.select();
                return false;
            }
            if (confirm("确定要注销卡：" + card + "?")) {
                $.post("/usercard/logoutUserCard.html", { id: id, card: card, fy: kf.val(), yj: yj.val(), bz: bz.val() }, function (dta) {
                    if (dta == -1) {
                        alert("该卡还有未归还的图书不能注销");
                    }
                    else {
                        alert("注销成功");
                        window.parent.frames["rightFrame"].location.reload();
                        ajax();
                    }
                });
            }
        });

    })
    function del(id, card) {
        if (confirm("是否确定")) {
            $.post("/userCard/deleteUserCard.html?" + (new Date()).getTime(), { res: id, card: card }, function (dta) {
                if (dta == "n") {
                    alert("抱歉，您操作的卡已经进入使用环节，不能删除");

                } else {
                    alert("删除成功");
                    window.parent.frames["rightFrame"].location.reload();
                }
            });
        }
    }

    function edit(id) {
        $.post("/usercard/getUserCardbyid.html?" + (new Date()).getTime(), { res: id }, function (dta) {
            userCard = $.evalJSON(dta);
            $.fillForm(userCard, "#mainForm");
            $("#textCard").val(userCard.uc_card)
        });
        $("input[name=buttsend]").val('修改');
        $("#uc_card").attr("disabled", "disabled");
        $("#uc_pass").attr("disabled", "disabled");
        $("#uc_chargeMode").attr("disabled", "disabled");
    }

    function detail(n) {
        $("#sutitle").html("注销会员卡[<span style='color:red;'>" + n.uc_card + "</span>]");
        $("#hiducid").val(n.uc_id);
        $("#hiducard").val(n.uc_card);
    }
</script>

     <div id="OpenWindow">
        <div id="signup-ct">
            <div id="OpenWindow-header">
                <h2 id="sutitle"></h2>
                <a href="#" class="modal_close"></a>
            </div> 
            <div class="txt-fld" id = "cz">
            <table style="width:100%;border:1px;border-color:White;text-align:left;" cellpadding="0" cellspacing="0">
            <tr><td style="border:1px;border-color:White;">退还费用：<input type="text" id="txtkf" name="txtkf" /></td></tr>
            <tr><td style="border:1px;border-color:White;">退还押金：<input type="text" id="txtyj" name="txtyj" /></td></tr>
            <tr><td style="border:1px;border-color:White;">退卡原因：<input type="text" id="txtbz" name="txtbz" />
            <input   type="button" name="buttloginout" id="buttloginout"  value="注销" />
            <input type="hidden" id="hiducid" name="hiducid" />
            <input type="hidden" id="hiducard" name="hiducard" />
            </td></tr>
            </table>
            </div>
            <div style="height:20px;"></div>
         </div>
</div>
    <table  cellspacing="0" id="seekForm">
        <tr>
            <th>
                会员充值卡查询
            </th>
        </tr>
        <tr>
        <td>
                卡号：<input type="text" name="card"/>
                类型<select id="selType" name="selType">
            <option value="-1">-请选择-</option>
             <%
                 foreach (string s in Enum.GetNames(typeof(DAL.Enums.cardType)))
                 {
                     int _v = (int)Enum.Parse(typeof(DAL.Enums.cardType), s);
                     Response.Write("<option value='" + _v + "'>" + s + "</option>");
                     Response.Write("<script>cardType['x" + _v + "']='" + s + "';</script>");
                 }
             %>
            </select>
            使用状态<select id="selState" name="selState">
            <option value="-1">-请选择-</option>
             <%
                 foreach (string s in Enum.GetNames(typeof(DAL.Enums.cardstate)))
                 {
                     int _v = (int)Enum.Parse(typeof(DAL.Enums.cardstate), s);
                     Response.Write("<option value='" + _v + "'>" + s + "</option>");
                     Response.Write("<script>cardState['x" + _v + "']='" + s + "';</script>");
                 }
             %>
            </select>
                添加时间：<input type="text" size="15" name="in_s"  value="<%=System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd") %>" class="date" />
                至<input type="text" size="15" name="in_e"  value="<%=System.DateTime.Now.ToString("yyyy-MM-dd")  %>" class="date" />
                </p>
                生效时间：<input type="text" size="15" name="sx_s"   class="date" />
                至<input type="text" size="15" name="sx_e"  class="date" />
                到期时间：<input type="text" size="15" name="dq_s"   class="date" />
                至<input type="text" size="15" name="dq_e"   class="date" />
             <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
        <tr>
        <td>
                排序：<input  type="checkbox"  name="ordercard" id="ordercard"/>卡号
                <input  type="checkbox" name="ordertype" id="ordertype"/>类型
                <input  type="checkbox" name="orderstate" id="orderstate"/>使用状态
                <input  type="checkbox" name="orderdate" id="orderdate"/>生效时间
                <input  type="checkbox" name="orderuser" id="orderuser"/>操作员
        </td>
        </tr>
    </table>
    <table  id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">充值卡列表</caption>
        <tr>
            <th>充值卡号</th>
            <th>充值卡类型</th>
            <th> 使用状态</th>
            <th>生效时间</th>
            <th>卡费</th>
            <th>押金</th>
            <th>备注</th>
            <th>操作员</th>
            <th>
            </th>
            </tr>
        <tbody name="mainlist">
        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table  cellspacing="0" id="mainForm">
        <tr>
            <th colspan="3">
                编辑充值卡
            </th>
        </tr>

       <tr>
            <td>充值卡号*</td>
            <td>
            <input id="txtcards"  />-<input id="txtcarde" /><input type="button" id="GenerateCard" name="GenerateCard" value="生成卡号" />
            <div style="height:5px"></div>
            <textarea  id="textCard" name="textCard" cols=""  rows="4" class="w400"></textarea></td>
            <td><span class="tsxx">多个卡号以，分隔</span></td>
        </tr>
         <tr>
            <td>会员充值卡密码</td>
            <td><input id="uc_pass" name="uc_pass" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>充值卡类型</td>
            <td>
            <select id="uc_chargeMode" name="uc_chargeMode">
            <option value="">-请选择-</option>
             <%
                 foreach (string s in Enum.GetNames(typeof(DAL.Enums.cardType)))
                 {
                     int _v = (int)Enum.Parse(typeof(DAL.Enums.cardType), s);
                     Response.Write("<option value='" + _v + "'>" + s + "</option>");
                 }
             %>
            </select></td>
            <td><span class="tsxx"></span></td>
        </tr>
                 <tr>
            <td>卡费</td>
            <td><input id="uc_kf" name="uc_kf" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
                 <tr>
            <td>押金</td>
            <td><input id="uc_yj" name="uc_yj" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
                 <tr>
            <td>备注</td>
            <td><input id="uc_bz" name="uc_bz" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
        <input type="hidden" id="uc_times" name="uc_times" /><input type="hidden" id="uc_useful" name="uc_useful"/>
        </tr>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttsend" class="btn1" style="width: 200px" 
                    value="保存" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</asp:Content>